<template>
  <div class="Login">
    <h1>{{ msg }}</h1>
  

  <el-form ref="form" :model="form" label-width="80px">
  <el-form-item label="帐号">
    <el-input v-model="form.username"></el-input>
  </el-form-item>

 <el-form-item label="密码">
    <el-input type="password" v-model="form.password"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="register">注册</el-button>
    <el-button type="primary" @click="onSubmit">登录</el-button>
  </el-form-item>
</el-form>
</div>
</template>

<script>
export default {
  name: 'Login',
  data () {
    return {
      msg: 'Login Page',
      form: {
          username: 'sky',
          password:'123'
        }
    }
  },
  methods: {
    onSubmit() {
      
      /*
      const h = this.$createElement;
      this.$notify({
      title: '标题名称',
      message: h('i', { style: 'color: teal'}, '这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案')
      }); */

      var vm = this;
      this.disablebtn = true;
      this.loginText = "登录中";
      this.$axios
        .post("login", {
          username: this.form.username,
          password: this.form.password
        })
        .then(function(res) {
           
          if (res.data.code == 201) {
            //登陆成功
            //读取token
            var token=res.data.data.token;
            sessionStorage.setItem("token",token);
            vm.$router.replace("/info");
          } else {
            vm.disablebtn = false;
            vm.loginText = "登录";

            vm.$alert(res.data.msg, '错误', {
              confirmButtonText: '确定'
            });
           

          }
        })
        .catch(function(err) {
          vm.disablebtn = false;
          vm.loginText = "登录";
          console.log(err);
        });
    },
    register() {
      this.$router.replace("/register");
    }
  }
};

</script>
